package com.lzj.server.service.impl;

import cn.dev33.satoken.stp.StpInterface;
import com.lzj.server.repository.mapper.AdminMapper;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自定义权限加载接口实现类 sa—token
 */
@Component
public class StpInterfaceImpl implements StpInterface {
    private final AdminMapper adminMapper;
    StpInterfaceImpl(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }

    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return adminMapper.selectPermission(NumberUtils.toLong(loginId.toString()));
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return adminMapper.selectRole(NumberUtils.toLong(loginId.toString()));
    }

}
